<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@include file="../../hy/common.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>库存盘点</title>
<%-- <script type="text/javascript"
	src="${pageContext.request.contextPath }/js/jquery-1.10.2.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath }/bootstrap/dist/js/bootstrap.js"></script>
<link rel="stylesheet"
	href="${pageContext.request.contextPath }/bootstrap/dist/css/bootstrap.css">
<link rel="stylesheet"
	href="${pageContext.request.contextPath }/plugins/layui/css/layui.css"
	media="all" />
<link rel="stylesheet"
	href="${pageContext.request.contextPath }/plugins/font-awesome/css/font-awesome.min.css">
<link rel="stylesheet"
	href="${pageContext.request.contextPath }/css/bootstrap-datetimepicker.min.css">
<script
	src="${pageContext.request.contextPath }/bootstrap-table/dist/bootstrap-table.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath }/plugins/layui/layui.js"></script>
<link
	href="${pageContext.request.contextPath }/bootstrap-table/dist/bootstrap-table.css"
	rel="stylesheet" />
<link
	href="${pageContext.request.contextPath }/pages/lf/css/bootstrap-editable.css"
	rel="stylesheet" />
<link
	href="${pageContext.request.contextPath }/css/bootstrap-datetimepicker.css"
	rel="stylesheet" />
<link
	href="${pageContext.request.contextPath }/css/bootstrapValidator.css"
	rel="stylesheet" />
<link
	href="${pageContext.request.contextPath }/css/bootstrap-editable.css"
	rel="stylesheet" />
<link
	href="${pageContext.request.contextPath }/css/bootstrap-datetimepicker.min.css"
	rel="stylesheet" />
<script src="${pageContext.request.contextPath }/js/toastr.min.js"></script>
<link rel="stylesheet" href="${pageContext.request.contextPath }/css/toastr.min.css">
<script
	src="${pageContext.request.contextPath }/pages/lf/js/bootstrap-editable.js"></script>
<script
	src="${pageContext.request.contextPath }/bootstrap-table/src/locale/bootstrap-table-zh-CN.js"></script>
<script
	src="${pageContext.request.contextPath }/js/bootstrap-datetimepicker.min.js"></script>
<script
	src="${pageContext.request.contextPath }/js/bootstrap-datetimepicker.js"></script>
<script
	src="${pageContext.request.contextPath }/js/bootstrap-datetimepicker.zh-CN.js"></script>
<script
	src="${pageContext.request.contextPath }/js/bootstrapValidator.js"></script>
<script
	src="${pageContext.request.contextPath }/js/bootstrap-editable.js"></script>
<script
	src="${pageContext.request.contextPath }/bootstrap-table/dist/extensions/editable/bootstrap-table-editable.js"></script>
<script
	src="${pageContext.request.contextPath }/js/bootstrapValidator.min.js"></script>
<script
	src="${pageContext.request.contextPath }/js/alert.js"></script> --%>
<% 
String id = request.getParameter("id");//用request得到 
String ptype = request.getParameter("ptype");//用request得到 
%> 	
<script type="text/javascript">
	$(function() {

		//1.初始化Table
		var oTable = new TableInit();
		oTable.Init();

		//2.初始化Button的点击事件
		var oButtonInit = new ButtonInit();
		oButtonInit.Init();
		//初始化提示框位置
		toastr.options.positionClass = 'toast-top-center';
		if('<%=ptype%>' == "物料"){
			$('#tb_departments').bootstrapTable('hideColumn', 'pdnumb');
		}else{
	  	 	$('#tb_departments').bootstrapTable('showColumn', 'pdnumb');
		}
		    $('#btn_fanh').click(function () {
		    	window.location.href='${pageContext.request.contextPath }/pages/lc/kucungl/pandian.jsp';
		    });
	});
	

	var TableInit = function() {
		var oTableInit = new Object();
		//初始化Table
		oTableInit.Init = function() {
			$('#tb_departments').bootstrapTable({
				url : '${pageContext.request.contextPath }/checkstock/selectfycsc.do', //请求后台的URL（*）
				method : 'get', //请求方式（*）
				toolbar : '#toolbar', //工具按钮用哪个容器
				striped : true, //是否显示行间隔色
				cache : false, //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
				pagination : true, //是否显示分页（*）
				sortable : false, //是否启用排序
				sortOrder : "asc", //排序方式
				queryParams : oTableInit.queryParams,//传递参数（*）
				sidePagination : "server", //分页方式：client客户端分页，server服务端分页（*）
				pageNumber : 1, //初始化加载第一页，默认第一页
				pageSize : 10, //每页的记录行数（*）
				pageList: [10,20,30], //可供选择的每页的行数（*）
				search : false, //是否显示表格搜索，此搜索是客户端搜索，不会进服务端，所以，个人感觉意义不大
				strictSearch : true,
				showColumns : false, //是否显示所有的列
				showRefresh : false, //是否显示刷新按钮
				minimumCountColumns : 2, //最少允许的列数
				clickToSelect : false, //是否启用点击选中行
				height :620, //行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度
				uniqueId : "id", //每一行的唯一标识，一般为主键列
				showToggle : false, //是否显示详细视图和列表视图的切换按钮
				cardView : false, //是否显示详细视图
				detailView : false,
				editable : true,
				columns : [ {
					checkbox : true
				}, {
					field : 'pdname',
					title : '品名'
				}, {
					field : 'pdnumb',
					title : '品编'
				},  {
					field : 'pnum',
					title : '库存数量',
				},  {
					field : 'pdnum',
					title : '实际数量',
					formatter:function(value,row,index){
		                  if(value=='' || value == null){return null;} 
		       			  else{return value;}                       
		     		},
	                editable:{
	               	    type:'text',
	                	validate:function(v){
	                		 if (!v) return '实际数量不能为空';
	                		 if (isNaN(v)) return '实际数量是数字';
	                	}
	                }
				},  {
					field : 'pdremark',
					title : '备注',
					formatter:function(value,row,index){
		                  if(value=='' || value == null){return null;} 
		       			  else{return value;}                       
		     		},
		     		editable:{
	               	    type:'text',
	                	validate:function(v){
	                		 
	                	}
	                }
				}],
				
			onEditableSave: function (field, row, oldValue, $el) {
			        	/* 如果提交之后的文本内容过多，表格的thead里面th的宽度和tbody里面td的宽度不对其的问题 */
			        	 $('#tb_departments').bootstrapTable('resetView');  
		        	   	//询问框
		    	     		Ewin.confirm({ message: "确认修改此数据吗？" }).on(function (e) {
		    	     	       if (!e) {
		    	     	         return;
		    	     	       } 
		    	     	      $.ajax({
		    		                type: "post",
		    		                url: "${pageContext.request.contextPath }/checkstock/updatexiangq.do",
		    		                data:"pdid="+row.pdid
		    		                +"&pdnum="+row.pdnum
		    		                +"&pdremark="+row.pdremark	
		    		                ,
		    		                success: function (data) {
		    		                  var result=eval('('+data+')');
		    		  				  if(result.success){
		    		  		    		   toastr.success("修改成功!");
		    		  		    		 $('#tb_departments').bootstrapTable('refresh');
		    		  				  }else{
		    		  					   toastr.error("修改失败!");
		    		  				   }
		    		                },
		    		                error: function () {
		    		                	toastr.warning('编辑失败!');
		    		                },
		    		            });
		    	     		}); 
		        	   	
			        	
			        },
			});
		};

		//得到查询的参数
		oTableInit.queryParams = function(params) {
			var temp = { //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
				limit : params.limit, //页面大小
				offset : params.offset, //页码
				pidd : <%=id %>, //盘点单主键
				pdname : $.trim($("#pdnamee").val()),
				pdnumb : $.trim($("#pdnumbb").val()),
			};
			return temp;
		};
		return oTableInit;
	};

	var ButtonInit = function() {
		var oInit = new Object();
		var postdata = {};

		oInit.Init = function() {
			//初始化页面上面的按钮事件
		};

		return oInit;
	};
	function search() {
		$('#tb_departments').bootstrapTable('refresh');
	}
</script>
</head>
<body>
	<div class="panel-body" style="padding-bottom: 0px;">
		<div class="panel panel-default">
			<div class="panel-heading">查询条件</div>
			<div class="panel-body">
				<form id="formSearch" class="form-horizontal">
					<div class="form-group" style="margin-top: 15px">
						<label class="control-label col-sm-1"
							for="txt_search_departmentname">品编</label>
						<div class="col-sm-2">
							<input type="text" class="form-control" id="pdnumbb">
						</div>
						<label class="control-label col-sm-1" for="txt_search_statu">品名</label>
						<div class="col-sm-2">
							<input type="text" class="form-control" id="pdnamee">
						</div>
						<div class="col-sm-3" style="text-align: left;">
						<button type="button" style="margin-left:50px" id="btn_query" 
                            	class="btn btn-primary" onclick="search()">查询</button>
						</div>
					</div>
				</form>
			</div>
		</div>

		<div id="toolbar" class="btn-group">
			<button id="btn_fanh" type="button" class="btn btn-default"
				data-toggle="modal" data-target="#myModal">
				<span class="glyphicon glyphicon-arrow-left" aria-hidden="true"></span>返回
			</button>
		</div>

		<table id="tb_departments"></table>
	</div>
</body>

</html>